Fix #3659 differently; sort HashMap keys before iteration.
authorNathanael Jones <nathanael.jones@gmail.com>
Wed, 8 Feb 2017 02:12:48 +0000 (19:12 -0700)
committerNathanael Jones <nathanael.jones@gmail.com>
Wed, 8 Feb 2017 02:12:51 +0000 (19:12 -0700)
Reverts 7a8b25a (and the need for it)

src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_rustc/custom_build.rs
tests/build-script.rs

index acc2fdf355ddfeef3170d33deb556c130b3096f4..ec3718955da2071d18bf608565cb932fd773de24 100644 (file)
@@ -492,7 +492,13 @@ fn scrape_target_config(config: &Config, triple: &str)
             rerun_if_changed: Vec::new(),
             warnings: Vec::new(),
         };
+        // We require deterministic order of evaluation, so we must sort the pairs by key first.
+        let mut pairs = Vec::new();
         for (k, value) in value.table(&lib_name)?.0 {
+            pairs.push((k,value));
+        }
+        pairs.sort_by_key( |p| p.0 );
+        for (k,value) in pairs{
             let key = format!("{}.{}", key, k);
             match &k[..] {
                 "rustc-flags" => {
@@ -528,10 +534,6 @@ fn scrape_target_config(config: &Config, triple: &str)
                     output.metadata.push((k.clone(), val.to_string()));
                 }
             }
-
-            // We randomized the data source with HashMaps, so we must sort the resulting vectors
-            // to produce a deterministic result
-            output.sort();
         }
         ret.overrides.insert(lib_name, output);
     }
index e187ab80066facb25924e3af82afb690ddc57609..ea3e0f98ca244ec78a5eb21cbd7633192c0b623e 100644 (file)
@@ -406,17 +406,6 @@ impl BuildOutput {
         }
         Ok((library_paths, library_links))
     }
-
-    /// Sort the contents of the struct for consistent hashing. 
-    /// Suggested if populated from a HashMap instead of an order-preserving data source
-    pub fn sort(&mut self){
-        self.library_paths.sort();
-        self.library_links.sort();
-        self.cfgs.sort();
-        self.metadata.sort();
-        self.rerun_if_changed.sort();
-        self.warnings.sort();
-    }   
 }
 
 /// Compute the `build_scripts` map in the `Context` which tracks what build
index 5f4dee7648f74f55ad70b0a91138df31bc13da56..647b7a064798c14f7314b9c54e0b0434de76a00e 100644 (file)
@@ -306,7 +306,7 @@ fn overrides_and_links() {
 [..]
 [..]
 [..]
-[RUNNING] `rustc --crate-name foo [..] -L bar -L foo`
+[RUNNING] `rustc --crate-name foo [..] -L foo -L bar`
 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
 "));
 }